package servlet_utente;

import java.io.IOException;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



import dao_utente.GestoreUtente;

/**
 * Servlet implementation class login
 */
@WebServlet("/login")
public class login extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private String username;
	private String password;
	private GestoreUtente gestore=new GestoreUtente();
       
   

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		HttpSession session=request.getSession(true);
		RequestDispatcher rd;
		
		username= request.getParameter("username");
		password=request.getParameter("password");
		bean.Utente utente=gestore.findUtente(this.username, this.password);
		
		if(utente!=null){
			session.setAttribute("utente", utente);
			response.sendRedirect("homePage");
		}
		else{
			rd=request.getRequestDispatcher("/login_error.html");
			rd.forward(request, response);
		}
	}

}
